#include<iostream>
using namespace std;
const int N = 510;
int n;
int a[N];
int main()
{
	int t;
	cin >> t;
	while (t--) {
		cin >> n;
		bool flag = 0;
		int idx = 0;
		for (int i = 1; i <= n; i++) {
			cin >> a[i];
			if (a[i] != i && !flag) {
				flag = 1;
				idx = i;
			}
		}
		if (!flag) {
			for (int i = 1; i <= n; i++) {
				cout << i << " ";
			}
			cout << endl;
		}
		else {
			int idx2 = 0;
			for (int i = 1; i <= n; i++) {
				if (a[i] == idx) {
					idx2 = i;
					break;
				}
			}
			for (int i = 1; i <= idx - 1; i++) {
				cout << i << " ";
			}
			for (int i = idx2; i >= idx; i--) {
				cout << a[i] << " ";
			}
			for (int i = idx2 + 1; i <= n; i++) {
				cout << a[i] << " ";
			}
			cout << endl;
		}
	}
	return 0;
}